package com.aluka.nirvana.framework.core.context;

import java.util.TimerTask;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 异步任务管理器
 * 
 */
public class AsyncContextManager
{
    /**
     * 操作延迟10毫秒
     */
    private static final int OPERATE_DELAY_TIME = 10;

    /**
     * 异步操作任务调度线程池
     */
    private ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10);

    /**
     * 单例模式
     */
    private static AsyncContextManager me = new AsyncContextManager();

    public static AsyncContextManager me()
    {
        return me;
    }

    /**
     * 执行任务
     * 
     * @param runnable 任务
     */
    public void execute(Runnable runnable){
        executor.schedule(runnable, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS);
    }
}
